<template>
	<view class="container">
		<navbar top="80rpx"></navbar>
		<view class="container">
			<!-- tab栏 -->
			<view class="header f-28 col-3">
				<view @tap.stop.prevent="bindHeaderTap(0)" :class="dataType == '0' ? 'active' : ''" data-type="all">
					<text>已兑换</text>
				</view>
				<view @tap="bindHeaderTap(1)" :class="dataType == '1' ? 'active' : ''" data-type="payment">
					<text>已发货</text>
				</view>
			</view>
			<view class="header-placeholder"></view>
			<!-- 订单列表 -->
			<view class="goods-detail-box">
				<view class="order-list" v-if="list.data">
					<view class="order" v-for="item in list.data" :key="item.order_id">
						<view class="item">
							<view class="img">
								<img :src="item.order_goods.goods_img" alt="">
							</view>
							<view>
								<view>订单编号：{{ item.order_no }}</view>
								<view class="text">兑换时间：{{ item.create_time }}</view>
								<view class="text" style="width: 100%;height: 30rpx; overflow: hidden;">商品名称：{{ item.order_goods.goods_name }}</view>
								<view class="price">{{ item.order_goods.goods_price }} 能量</view>
								<view class="btn" v-if="item.express_company != '' || item.express_no != ''" @click="isPop(item)">
									物流
								</view>
							</view>
						</view>
						
					</view>
				</view>
				<view v-if="!isLoading && !list.data.length">
					<view class="yoshop-notcont">
						<text class="iconfont icon-wushuju"></text>
						<text class="cont">暂无订单</text>
					</view>
				</view>
			</view>
		</view>
			<view class="zz" v-show="isPwd">
				<view class="popup">
					<view class="title">
						物流信息
					</view>
					<view class="">
						物流公司:{{express_company}}
					</view>
					<view class="">
						快递号:{{express_no}}
					</view>
					<view class="btn" style="border-top:1rpx solid #dfdfdf;height: 100rpx;text-align: center;line-height: 100rpx;">
						<view @click="isPwd = false" style="width: 295rpx;height: 100%;border-right: 1rpx solid #dfdfdf;">取消</view>
						<view @click="isCopy()" style="width: 300rpx;height: 100%;">复制单号</view>
					</view>
				</view>
			</view>
	</view>
</template>

<script>
	import navbar from "@/components/navbar/navbar";
	const app = getApp(); // 枚举类：发货方式
	export default {
		components: {
			navbar,
		},
		data() {
			return {
				payTypeIndex: 0,
				userInfo: uni.getStorageSync('userInfo'),
				curPayType: 0,
				dataType: '0', // 列表类型
				list: [], // 订单列表
				isLoading:false,
				isPwd:false,
				page:1,
				express_company:'',//快递公司
				express_no:'',//快递单号
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			let _this = this;
			// 设置数据类型
			_this.setData({
				dataType: options.type || '0'
			});
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow() {
			// 获取订单列表
			this.list = []
			this.page = 1
			this.getOrderList()
		},
		onHide() {
			clearTimeout(this.times)
		},
		onPullDownRefresh() {
			this.list = []
			this.page = 1
			this.getOrderList()
		},
		//触底加载
		onReachBottom() {
			console.log('触底')
			// 已经是最后一页
			if (this.page >= this.list.last_page) {
				app.showToast('已经到底了哦~');
			}else{
				this.page = ++this.page
				this.getOrderList(true);
			} // 加载下一页列表
			console.log(this.page)
			
		},
		methods: {
			/**
			 * 获取订单列表
			 */
			getOrderList(isPage, page) {
				let _this = this;

				app._post_form(
					'Jadegoods/getOrderList', {
						page: _this.page,
						limit:10,
						delivery: _this.dataType
					},
					(result) => {
						let resList = result.data.list;
						let dataList = _this.list;
						if (isPage == true) {
							_this.setData({
								'list.data': dataList.data.concat(resList.data),
								isLoading: false
							});
						} else {
							_this.setData({
								list: resList,
								isLoading: false
							});
						}
					},null,function(){
						uni.stopPullDownRefresh();
					}
				);
			},

			/**
			 * 切换标签
			 */
			bindHeaderTap(e) {
				console.log(e)
				if(this.dataType != e){
					this.page = 1
				}
				this.dataType = e
				this.getOrderList()
			},
			//打开快递弹窗
			isPop(e){
				this.isPwd = true
				this.express_company = e.express_company
				this.express_no = e.express_no
			},
			//复制
			isCopy(){
				uni.setClipboardData({
				    data: this.express_no, // e是你要保存的内容
				    success: function () {
						uni.showToast({
							title:'复制成功',
							icon:'none'
						})
				    }
				})
			}
		}
	};
</script>
<style>
	page {
		background: #fff !important;
	}
</style>
<style lang="scss" scoped>
	.container{
		box-sizing: border-box;
		// min-height: 100vh;
		// padding:110rpx 50rpx 40rpx 50rpx;
		// background:  #000 url('https://qiniu.wiod.cn/detail/userBg.png') 40rpx 117rpx no-repeat;
		background:  #000;
		background-size: 710rpx 512rpx;
	}
	.header {
		width: 100%;
		height: 88rpx;
		border-bottom: 1rpx solid #e4e4e4;
		display: flex;
		background: #fff;
		line-height: 88rpx;
		position: fixed;
		top: 0;
		/* top: 44px;
		top: calc(44px + constant(safe-area-inset-top));
		top: calc(44px + env(safe-area-inset-top)); */
		z-index: 100;
	}

	.header-placeholder {
		height: 88rpx;
	}

	.header view {
		flex: 1;
		text-align: center;
		padding: 0 15rpx;
	}

	.header view text {
		display: block;
	}

	.header view.active text {
		color: $uni-text-color-main;
		border-bottom: 3rpx solid $uni-border-color-main;
	}

	.order-list {
		padding: 0 40rpx;
	}

	.goods-detail-box {
		padding-bottom: 40rpx;
	}

	.order {
		background-color: #f9f9f9;
		border-radius: 30rpx;
		margin-top: 40rpx;
		padding: 20rpx 40rpx 40rpx;
		font-size: 24rpx;
		font-weight: 500;
		color: #333333;
		position: relative;
		.item{
			display: flex;
			.img {
				width: 216rpx;
				height: 190rpx;
				margin-right: 16rpx;
			
				img {
					width: 100%;
					height: 100%;
					border-radius: 4rpx;
					// background-color: #fff;
				}
			}
			.text{
				margin-top: 20rpx;
			}
			.price {
				margin-top: 30rpx;
				font-size: 28rpx;
				font-weight: bold;
				color: #FF602E;
			}
			.btn{
				width: 100rpx;
				height: 60rpx;
				background-color: #000;
				color: #fff;
				border-radius: 10rpx;
				text-align: center;
				line-height: 60rpx;
				position: absolute;
				bottom: 20rpx;
				right: 30rpx;
			}
		}
	}
	.zz{
		  position: fixed;
		  top: 0;
		  left: 0;
		  right: 0;
		  bottom: 0;
		  z-index: 14;
		  background: rgba(0, 0, 0, 0.5);
		  display: flex;
		  justify-content: space-around;
		  align-items: center;
		  z-index: 3;
		  .popup{
			  padding: 30rpx;
			  padding-bottom: 0;
			  border-radius: 20rpx;
			  width: 600rpx;
			  height: 450rpx;
			  background-color: #fff;
			  display: flex;
			  flex-direction: column;
			  justify-content: space-between;
			  .title{
				  margin-top: 20rpx;
				  text-align: left;
				  height: 80rpx;
				  line-height: 80rpx;
				  font-weight: 700;
				  // border-bottom: 1rpx solid #999;
			  }
			  .pwd{
				  margin-top: 50rpx;
				  width: 100%;
				  background-image: none !important;
				/deep/ Input{
					  width: 80% !important;
					  font-size: 30rpx;
					  height: 74rpx;
					  text-align: center;
					  background-color: #F8F5F5;
					  border-radius: 5rpx;
					  // border: 0.5rpx solid #999 !important;
				  }
				  
			  }
			  .btn{
				  display: flex;
			  }
		  }
	}
</style>
